import React from "react";
import {
  BrowserRouter,
  NavLink,
  Route,
  Switch, 
  Redirect
} from "react-router-dom";
import Home from "./home";
const Index = () => {
  return (
    <BrowserRouter>
      <nav>
        <NavLink
          to={{
            pathname: "/home",
            search: window.sessionStorage.getItem("user")
          }}
        >
          我是首页
        </NavLink>
        <NavLink to="/news">我是新闻</NavLink>
      </nav>
      {/* 
    【*】在Swith组件里使用Redirect重定向组件的时候，必须注意书写顺序，如果Redirect写在了Swith内部的顶端，那么Re'di're
    */}
      <main>
        <Switch>
          <Route path="/home" component={Home} />
          <Route path="/news" component={() => <div>我是新闻</div>} />
          <Redirect from="/" to="/home" />
        </Switch>
      </main>
    </BrowserRouter>
  );
};

export default Index;
